<template>
    <div>
        <h1>医生添加页面</h1>
        <table class="table table-bordered" >
            <tbody>
                <tr>
                    <td>医生姓名：</td>
                    <td><input type="text" v-model="info.name"></td>
                </tr>
            <tr>
          <td >门店图片</td>
          <td>
            <input type="file" @change="img" />
            <img
              :src="info.photo"
              width="100"
              height="100"
              v-if="info.photo != ''"
            />
          </td>
        </tr>
       <tr>
          <td>选择科室</td>
        <td>
            <select v-model="info.keShiid">
              <option value="">请选择</option>
              <option :value="item.id" v-for="item in data.list">
                {{ item.name   }}
              </option>
            </select>
          </td>
       </tr>
       <tr>
        <td>创建时间</td>
        <td>
          <input type="date" v-model="info.time" />
        </td>
       </tr>
       <tr>
        <td></td>
        <td>
          <button @click="add">添加</button>
        </td>
       </tr>

            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import axios from 'axios';
import moment from 'moment';
import { useRouter, useRoute } from 'vue-router';

const router = useRouter();
const route = useRoute();
let info:any=reactive({
    
    name: "",
      photo: "",
      keShiid: '',
     time: '',
     isdel:false,
      keshiName: "",
})
let data:any=reactive([
   
]);
onMounted(()=>{
yisheng(); 
})
const img =(img1:any)=>{
    let obj=img1.target.files[0];
    let f=new FormData();
    f.append('file',obj)
    axios({
        url:'/api/tu/img',
        data:f,
        method:'post',
        
        
    })
    .then(res=>{
        info.photo=res.data;
        if(res.data=="大于2M"){
          alert('图片大小不能大于2M')
          return; 
        }
    })
}
const add=()=>{
 if(info.name==''){
   alert('医生姓名不能为空')
   return; 
 }
 axios({
   url:'/api/yisheng/Addyisheng',
   method:'post',
   data :info
 }) 
.then(res=>{
    if(res.data==-1){
      alert('医生姓名不能重复')
      return;
    }
   if(res.data==1){
      alert('添加成功')
      router.push('/ShowYiSheng');
   }
   else{
     alert('添加失败')
     return; 
   }
 }) 

}
const yisheng=()=>{
 axios({
   url:'/api/yisheng/showkeshi',
   method:'get',
   data:info
 }) 
.then(res=>{
   data.list=res.data;
   console.log(data.list);})
   .catch(err=>{
    console.log(err);
  })
}


</script>

<style scoped>

</style>